<?php
session_start();
require_once("../config/include_tokyo.inc.php");
require_once("../class/Common_Function.php");

//访问权限验证
$userRole = $_SESSION['user_role'];
if($userRole == 1){
	//管理员
}else{
	if($userRole > 0){
		$url = "../index.php?loginError=2";//没权限
	}else{
		$url = "../index.php?loginError=3";//没登录
	}	
	echo "<script language='javascript' type='text/javascript'>";
	echo "window.location.href='$url'";
	echo "</script>";
}

//get post value
$doFlag = $_POST["doFlag"];
$id = $_POST["id"];

//delete user
if($doFlag == "doDelete"){
	$sqlDel = "delete from users where id= $id";
	$db->Execute($sqlDel);
	$strShow = "*****************************************<br>";
	$strShow = $strShow."删除成功：<br>";
	$strShow = $strShow."用户ID：$id<br>";
	$strShow = $strShow."*****************************************<br>";
	echo $strShow;
}


//get user list
$sql_select = "select * from users order by id desc";
$result = $db->Execute($sql_select);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<!--Begin:head-->
<? $pageTitle = "用户列表"; ?>
<?php include("../head.php"); ?>
<!--End:head-->


<body>
<?php include("../topMenu.php"); ?>


<?php include("userMenu.php"); ?>


<form name="listForm" action="userList.php" method="post">
<div id="container" >	

<div class="grayTable">	
<h4>用户列表:</h4>
<table >
<thead>
	<tr>
		<th scope="col" >用户ID</th>
	    <th scope="col" >用户名称</th>
		<th scope="col" >用户密码</th>
		<th scope="col" >用户角色</th>
		<th scope="col" width=200>操作</th>
	</tr>
</thead>

<tbody>
	<?php
	$commonFunction = new Common_Function();
	while (!$result->EOF) {
		$id = $result->fields['id'];
		$userName = $result->fields['user_name'];
		$userPassword = $result->fields['user_password'];
		$userRole = $result->fields['user_role'];
		$strTR = "<tr >";
		$strTR = $strTR ."<td>".$id ."</td>";
		$strTR = $strTR ."<td>".$userName ."</td>";
		$strTR = $strTR ."<td>".$userPassword ."</td>";
		$strTR = $strTR ."<td>".$commonFunction->getRoleName($userRole)."</td>";
		$strTR = $strTR ."<td align=center>"."<a href='javascript:doEdit($id)' class='button icon edit'>编辑</a>";
		$strTR = $strTR ."<a href='javascript:doDelete($id)' class='button icon remove'>删除</a></td>";
		$strTR =  $strTR ."</tr >";
		echo $strTR;
		$result->MoveNext();
	}
	?>
</tbody>

					
</table>	
</div>



</div><!--end container -->

<input type="hidden" name="doFlag" id="doFlag" >
<input type="hidden" name="id" id="id" >
</form>


<form name="inputForm" action="userInput.php" method="post">
<input type="hidden" name="editId" id="editId" >
</form>

</body>




</html>

<script>

function doEdit(id){
	document.getElementById('editId').value = id;
	document.inputForm.submit();
}

function doDelete(id){
	if(confirm("是否删除这条记录,删除后不可恢复,是否继续?")){ 
		document.getElementById('doFlag').value = "doDelete";
		document.getElementById('id').value = id;
		document.listForm.submit();
	}else{
		return;
	}
}


</script>

